fix(repeater/sensor/room_server/secure_chat cli): permanent lockup without CR - #2978
fix(repeater/sensor/room_server/secure_chat cli): permanent lockup without CR#2978fkallay1 wants to merge 1 commit into
Conversation
|
Gentle nudge on this one, no urgency intended.
For context, the change is one line repeated across the repeater, sensor, room server and secure chat Happy to rebase, split it per firmware, or narrow the scope if any of that would make it easier to |
be236e1 to
667e942
Compare
…thout CR The buffer-full branch writes the forced '\r' to command[sizeof-1], but the line-complete check below tests command[len-1] (== sizeof-2 when the buffer is full), so the line never completes: the read loop's condition (len < sizeof-1) stays false forever and the CLI stops reading serial input until reboot. Writing at [sizeof-1] also overwrites the string's NUL terminator, so the next strlen() reads past the buffer (UB). Write the '\r' at command[sizeof-2] instead — exactly the position the completion check tests. The overflowed input is then processed as an (unknown) command, the buffer resets, and the CLI keeps working. Reproduced on hardware (T1000-E repeater): ~53 arrow-key presses in an attached terminal (3-byte ESC[A escape sequences, 159 bytes with no CR) filled the buffer and the CLI never accepted a command again until reboot. The same copy-pasted pattern is fixed in simple_repeater, simple_sensor, simple_room_server and simple_secure_chat.
667e942 to
f76c465
Compare
Problem
The serial CLI loop in the examples locks up permanently when ≥159 characters arrive without a CR. The buffer-full branch tries to force-complete the line:
but the line-complete check below tests
command[len - 1], which iscommand[sizeof-2]when the buffer is full — one position before the byte just written. The result:len < sizeof(command)-1) stays false forever — the CLI stops reading serial input entirely until reboot. Everything else (mesh, radio) keeps running, so the node looks alive but ignores all commands.[sizeof-1]also overwrites the string's NUL terminator, so the nextstrlen(command)reads past the end of the buffer (UB).How it triggers in practice
Reproduced on hardware (T1000-E repeater, remote site): the serial console was shared through tmux+picocom, and ~53 arrow-key presses in the attached terminal (3-byte
ESC[Aescape sequences, 159 bytes with no CR) filled the buffer. The CLI never accepted a command again until the device was rebooted.Any input source that produces long CR-less byte runs triggers it: pasted text, cursor-key escape sequences, line noise on a hardware UART, or a script sending LF-only line endings (LF is skipped, other bytes accumulate).
Fix
Write the forced
'\r'atcommand[sizeof-2]— exactly the position the completion check tests. The overflowed input is then processed as an (unknown) command, the buffer resets, and the CLI keeps working.The same copy-pasted pattern exists in four examples; all are fixed:
examples/simple_repeater/main.cppexamples/simple_sensor/main.cppexamples/simple_room_server/main.cppexamples/simple_secure_chat/main.cppTesting
vercommand answers normally.t1000e_repeateron this branch (no other changes).